using System;
using System.Collections.Generic;
using System.Text;

namespace BTV.Base
{
    public class BTVProgramSchedule
    {
        private BTVProgram _program;

        public BTVProgram Program
        {
            get { return _program; }
            set { _program = value; }
        }
        private List<BTVSchedule> _schedules;

        public List<BTVSchedule> Schedules
        {
            get { return _schedules; }
            set { _schedules = value; }
        }

        public BTVProgramSchedule(BTVProgram p, List<BTVSchedule> s)
        {
            _program = p;
            _schedules = s;
        }

        public void AddSchedule(BTVSchedule s)
        {
            _schedules.Add(s);
        }

        public BTVProgramSchedulePairCollection ConvertToProgramSchedulePairCollection()
        {
            BTVProgramSchedulePairCollection pspc = new BTVProgramSchedulePairCollection();
            foreach (BTVSchedule s in Schedules)
            {
                BTVProgramSchedulePair p = new BTVProgramSchedulePair(Program, s);
                pspc.Add(p);
            }
            return pspc;
        }
    }

    public class BTVScheduleSelectionDictionary : Dictionary<DateTime, BTVProgramSchedulePairCollection>
    {
        public BTVScheduleSelectionDictionary() : base() { }
    }

    public class BTVScheduleSelection : List<BTVProgramSchedule>
    {
        public BTVScheduleSelection() : base() { }
    }

    public class BTVScheduleSelectionSortableDictionary : IComparable<BTVScheduleSelectionSortableDictionary>
    {

        private DateTime _date;

        public DateTime Date
        {
            get { return _date; }
            set { _date = value; }
        }

        private BTVProgramSchedulePairCollection _progPairCollection;

        public BTVProgramSchedulePairCollection ProgPairCollection
        {
            get { return _progPairCollection; }
            set { _progPairCollection = value; }
        }

        #region IComparable<BTVScheduleSelectionSortableDictionary> Members

        public int CompareTo(BTVScheduleSelectionSortableDictionary other)
        {
            return _date.CompareTo(other.Date);
        }

        #endregion
    }

    public class BTVProgramSchedulePair : IComparable<BTVProgramSchedulePair>
    {
        private BTVProgram _program;

        public BTVProgram Program
        {
            get { return _program; }
            set { _program = value; }
        }
        private BTVSchedule _schedule;

        public BTVSchedule Schedule
        {
            get { return _schedule; }
            set { _schedule = value; }
        }

        public BTVProgramSchedulePair(BTVProgram p, BTVSchedule s)
        {
            _program = p;
            _schedule = s;
        }

        #region IComparable<BTVProgramSchedulePair> Members

        public int CompareTo(BTVProgramSchedulePair other)
        {
            return Schedule.StartTime.CompareTo(other.Schedule.StartTime);
        }

        #endregion
    }

    public class BTVProgramSchedulePairCollection : List<BTVProgramSchedulePair>
    {
        public BTVProgramSchedulePairCollection()
            : base() { }

        new public void Add(BTVProgramSchedulePair p)
        {
            if (!this.Contains(p))
            {
                base.Add(p);
            }
        }
    }
}
